/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fertigproz;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author zimmbi
 */
public class MySQLDriver {

    private String host;
    private String username;
    private String password;
    private String dbname;
    private Connection conn;

    public MySQLDriver(String host, String username, String password, String dbname) {
        this.host = host;
        this.username = username;
        this.password = password;
        this.dbname = dbname;
    }

    public boolean connect() {
        String url = "jdbc:mysql://" + host + "/" + dbname;
        try {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            conn = (Connection) DriverManager.getConnection(url, username, password);
            return true;
        } catch (SQLException ex) {
        } catch (InstantiationException ex) {
        } catch (IllegalAccessException ex) {
        } catch (ClassNotFoundException ex) {
        }
        return false;
    }

    public ResultSet query(String query) throws SQLException {
        Statement s = (Statement) conn.createStatement();
        s.executeQuery(query);
        return s.getResultSet();
    }
}
